package org.example.trade.controller;

import cn.dev33.satoken.stp.StpUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.api.order.OrderFacadeService;
import org.example.api.order.model.TradeOrderVO;
import org.example.api.order.request.OrderPageQueryRequest;
import org.example.api.pay.service.PayFacadeService;
import org.example.base.response.PageResponse;
import org.example.web.vo.MultiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lly
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderFacadeService orderFacadeService;

    @Autowired
    private PayFacadeService payFacadeService;


    /**
     * 订单列表
     *
     * @param state
     * @param pageSize
     * @param currentPage
     * @return
     */
    @GetMapping("/orderList")
    public MultiResult<TradeOrderVO> orderList(String state, int pageSize, int currentPage) {
        String userId = (String) StpUtil.getLoginId();
        OrderPageQueryRequest orderPageQueryRequest = new OrderPageQueryRequest();
        orderPageQueryRequest.setBuyerId(userId);
        orderPageQueryRequest.setState(state);
        orderPageQueryRequest.setCurrentPage(currentPage);
        orderPageQueryRequest.setPageSize(pageSize);
        PageResponse<TradeOrderVO> pageResponse = orderFacadeService.pageQuery(orderPageQueryRequest);
        return MultiResultConvertor.convert(pageResponse);
    }
}